import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';

class SearchItem extends StatelessWidget {
  final String title;
  final Widget? action;
  final List<String> tags;

  SearchItem(this.title, {Key? key, required this.tags, this.action})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    double width = MediaQuery.of(context).size.width;
    return Container(
      width: width,
      padding: EdgeInsets.symmetric(horizontal: 20),
      child: Column(
        children: [
          _header(),
          BrnSelectTag(
            tags: tags,
            isSingleSelect: true,
            fixWidthMode: false,
            spacing: 10,
            themeData: BrnTagConfig(
                tagRadius: 15,
                tagBackgroundColor: Colors.white12,
                selectedTagBackgroundColor: Colors.white12,
                tagTextStyle: BrnTextStyle(color: Colors.white, fontSize: 14),
                selectTagTextStyle:
                    BrnTextStyle(color: Colors.white, fontSize: 14)),
            tagHeight: 30,
            onSelect: (selectedIndexes) {
              BrnToast.show(selectedIndexes.toString(), context);
            },
          ),
          Divider(
            height: 20,
            color: Colors.transparent,
          ),
        ],
      ),
    );
  }

  Widget _header() {
    Widget _title = Text(
      title,
      style: TextStyle(color: Colors.white30, fontSize: 14),
    );
    List<Widget> children = [_title];
    if (action != null) {
      children.add(Spacer());
      children.add(action!);
    }
    return Container(
      height: 30,
      child: Row(
        children: children,
      ),
    );
  }
}
